package vip.sweet.sys.modular.department.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.sweet.aop.annotations.LocalLock;
import vip.sweet.common.annotations.CommonOperationLog;
import vip.sweet.common.enums.BusinessType;
import vip.sweet.common.enums.ResponseEnum;
import vip.sweet.common.response.CommonResponse;
import vip.sweet.sys.modular.department.params.AddDepartmentParams;
import vip.sweet.sys.modular.department.service.DepartmentService;

/**
 * @author ASUS
 * @Date 2025/4/8 11:31
 * @Descripition TODO
 */
@RestController
@RequestMapping("/sys/department")
@Tag(name = "部门管理控制器")
public class DepartmentController {
    @Resource
    private DepartmentService departmentService;
    @Operation(summary = "新增部门")
    @PostMapping("/add")
    @CommonOperationLog(title = "新增部门",businessType = BusinessType.INSERT)
    @LocalLock(key = "sys:department:add:{#addDepartmentParams.name}:{#addDepartmentParams.parentId}")
    public CommonResponse add(@RequestBody @Validated AddDepartmentParams addDepartmentParams){
        return departmentService.add(addDepartmentParams) ? CommonResponse.success("添加成功") : CommonResponse.error(ResponseEnum.ERROR, "添加失败");
    }
    @Operation(summary = "获取部门树")
    @GetMapping("/tree")
    public CommonResponse tree(){
        return CommonResponse.success(departmentService.tree());
    }
}
